export default {
    //这个state要用闭包是因为独立
    state: () => ({
        name: "xzc",
        age: 36,
    }),
    //同外面的getters，不能重名
    getters: {
        fullname(state) {
            return state.name + state.age;
        },
        //此getters仅限于user
        fullname2(state, getters) {
            return getters.fullname + "-2";
        },
        //此rootState指向全局getters
        fullname3(state, getters, rootState) {
            return getters.fullname2 + rootState.num;
        }
    },
    //同外面的mutations，不能重名
    mutations: {
        setname(state, payload) {
            state.name = payload;
        },
    },
    actions: {
        //context里面的东西
        dosome({state, commit, getters, rootGetters, rootState}, payload) {
            setTimeout(() => {
                rootState.num = 100;
                commit('setname', payload);
            }, 2000);
        }
    },
};
